package config;

import com.alibaba.druid.pool.DruidDataSource;
import com.zm.dao.IAccountDao;
import com.zm.services.IAcountServices;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;

import javax.sql.DataSource;

public class JdbcConfigruation {

    @Value("${driverClassName}")
    private String driverClassName;
    @Value("${url}")
    private String url;
    @Value("${user}")
    private String username;
    @Value("${password}")
    private String password;

    //使用bean注解是将方法的返回值存入ioc容器当中
    //不写id值，默认为方法名
    @Bean(name="runner")
    @Scope("prototype")
    public QueryRunner createRunner(@Qualifier("dataSource3") DataSource dataSource, IAcountServices AccountServicesImpl ){

        return new QueryRunner(dataSource);
    }

    @Bean("dataSource3")
    public DruidDataSource createDataPool(){
        DruidDataSource ds=new DruidDataSource();
        ds.setDriverClassName(driverClassName);
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        return ds;

    }
}
